const gulp=require("gulp");
const htmlmin=require("gulp-htmlmin");
const jsmin=require("gulp-uglify");
const cssmin=require("gulp-clean-css");
const autofixmin=require("gulp-autoprefixer");
const imgmin=require("gulp-imagemin");
const babel=require("gulp-babel");
gulp.task("testHtmlmin",function () {
    var options={
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };
    gulp.src('client/src/*.html')
        .pipe(htmlmin(options))
        .pipe(gulp.dest('client/dist'));
});
gulp.task("testJsmin",function () {
    gulp.src(['client/src/js/*/*.js','client/src/js/*.js'])
        .pipe(babel())
        .pipe(jsmin())
        .pipe(gulp.dest('client/dist/js'));
});
gulp.task("testImgmin",function () {
    var options={
        optimizationLevel: 5, //类型：Number  默认：3  取值范围：0-7（优化等级）
        progressive: true, //类型：Boolean 默认：false 无损压缩jpg图片
        interlaced: true, //类型：Boolean 默认：false 隔行扫描gif进行渲染
        multipass: true //类型：Boolean 默认：false 多次优化svg直到完全优化
    };
    gulp.src('client/src/img/*/*.{png,jpg,gif,ico,jpeg}')
        .pipe(imgmin(options))
        .pipe(gulp.dest('client/dist/img'))
});
gulp.task('testAutoFx', function () {
    gulp.src('client/src/css/**.css')
        .pipe(autofixmin({
            browsers: ['last 2 versions', 'Android >= 4.0'],
            cascade: true, //是否美化属性值 默认：true 像这样：
            //-webkit-transform: rotate(45deg);
            //        transform: rotate(45deg);
            remove:true //是否去掉不必要的前缀 默认：true
        }))
        .pipe(gulp.dest('client/src/css'));
});
gulp.task("testCssmin",function () {
    var options={
        advanced: false, //类型：Boolean 默认：true [是否开启高级优化（合并选择器等）]
        compatibility: 'ie7', //保留ie7及以下兼容写法 类型：String 默认：''or'*' [启用兼容模式； 'ie7'：IE7兼容模式，'ie8'：IE8兼容模式，'*'：IE9+兼容模式]
        keepBreaks: true, //类型：Boolean 默认：false [是否保留换行]
        keepSpecialComments: '*'
    };
    gulp.src('client/src/css/**.css')
        .pipe(cssmin(options))
        .pipe(gulp.dest('client/dist/css'))
});

gulp.task("default", ["testHtmlmin","testAutoFx", "testCssmin", "testImgmin","testJsmin"]);